<?php
namespace Home\Model;

use Think\Model;

class MemcacheModel{
	//存储实例化出来的模型
	private $m;
	private $error;
	private $debug=true;

	//构造方法
	public function __construct(){
		$this->m = new \Memcache();
		$this->m->connect('127.0.0.1',11211);
	}

	public function mem($key,$value=null,$time=0){
		$num = func_num_args();
		if($num == 1){
			return $this->get($key);
		}else{
			if($value == null){
				$this->delete($key);
			}else{
				$this->set($key,$value,$time);
			}
		}
	}

	private function set($key,$value,$time=0){
		$this->m->set($key,$value,MEMCACHE_COMPRESSED,$time);
	}

	private function get($key){
		return $this->m->get($key);
	}

	private function delete($key){
		$this->m->delete($key);
	}

	private function getError(){
		$this->error = $this->m->getResultMessage();
	}
}